package com.ruoyi.api.kehu;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JiajiaProxyApplication;
import com.ruoyi.system.service.IJiajiaProxyApplicationService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 代理申请记录Controller
 *
 * @author ruoyi
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/api/kehu/jiajiaProxyApplication")
public class ApiJiajiaProxyApplicationController {

    @Autowired
    private IJiajiaProxyApplicationService jiajiaProxyApplicationService;

    /**
     * 新增保存代理申请记录
     */
    @Log(title = "代理申请记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaProxyApplication jiajiaProxyApplication) {
         try {
             return AjaxResult.success(jiajiaProxyApplicationService.insertJiajiaProxyApplication(jiajiaProxyApplication));
         }catch (Exception e){
             return AjaxResult.error(e.getMessage());
         }
    }

    /**
     * 修改代理申请记录
     */
    @GetMapping("/edit/{id}")
    public AjaxResult edit(@PathVariable("id") Long id) {
        JiajiaProxyApplication jiajiaProxyApplication = jiajiaProxyApplicationService.selectJiajiaProxyApplicationById(id);
        return AjaxResult.success(jiajiaProxyApplication);
    }

    /**
     * 修改保存代理申请记录
     */
    @Log(title = "代理申请记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaProxyApplication jiajiaProxyApplication) {
        return AjaxResult.success(jiajiaProxyApplicationService.updateJiajiaProxyApplication(jiajiaProxyApplication));
    }


    /**
     * 我的代理申请记录
     */
    @ApiOperation("我的代理申请记录")
    @GetMapping("/list")
    public AjaxResult itSMine(Integer status) {
        List<JiajiaProxyApplication> jiajiaProxyApplication = jiajiaProxyApplicationService.selectItSMine(status);
         return AjaxResult.success(jiajiaProxyApplication);
    }


}
